package NC;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class NC80 {
    private ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
    private Queue<TreeNode> queue = new LinkedList<>();
    ArrayList<ArrayList<Integer>> Print(TreeNode pRoot) {
        if(pRoot==null) return new ArrayList<>();
        queue.offer(pRoot);
        while (!queue.isEmpty()){
            int len = queue.size();
            ArrayList<Integer> temp = new ArrayList<>();
            for (int i = 0; i < len; i++) {
                TreeNode now = queue.poll();
                temp.add(now.val);
                if(now.left!=null) queue.offer(now.left);
                if(now.right!=null) queue.offer(now.right);
            }
            ans.add(new ArrayList<>(temp));
        }
        return ans;
    }

}